<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.10"/>
<title>Introduction_to_Algorithms: IntroductionToAlgorithm::QueueAlgorithm::MinQueue&lt; T, TKeyType &gt; Class Template Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { init_search(); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">Introduction_to_Algorithms
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.10 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li class="current"><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="annotated.html"><span>Class&#160;List</span></a></li>
      <li><a href="classes.html"><span>Class&#160;Index</span></a></li>
      <li><a href="hierarchy.html"><span>Class&#160;Hierarchy</span></a></li>
      <li><a href="functions.html"><span>Class&#160;Members</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="summary">
<a href="#pub-types">Public Types</a> &#124;
<a href="#pub-methods">Public Member Functions</a> &#124;
<a href="#pro-methods">Protected Member Functions</a> &#124;
<a href="#pri-attribs">Private Attributes</a> &#124;
<a href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue-members.html">List of all members</a>  </div>
  <div class="headertitle">
<div class="title">IntroductionToAlgorithm::QueueAlgorithm::MinQueue&lt; T, TKeyType &gt; Class Template Reference</div>  </div>
</div><!--header-->
<div class="contents">

<p>MinQueue：最小优先级队列，算法导论第6章6.5节  
 <a href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html#details">More...</a></p>

<p><code>#include &lt;<a class="el" href="minqueue_8h_source.html">minqueue.h</a>&gt;</code></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pub-types"></a>
Public Types</h2></td></tr>
<tr class="memitem:a8f2f5b5d2b7097bbc6edda7b9c9228a6"><td class="memItemLeft" align="right" valign="top">typedef std::function&lt; bool(std::shared_ptr&lt; T &gt;, std::shared_ptr&lt; T &gt;)&gt;&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html#a8f2f5b5d2b7097bbc6edda7b9c9228a6">CompareType</a></td></tr>
<tr class="separator:a8f2f5b5d2b7097bbc6edda7b9c9228a6"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a391cb754ab172d1d4cdefd34130b917c"><td class="memItemLeft" align="right" valign="top">typedef std::function&lt; TKeyType &amp;(std::shared_ptr&lt; T &gt;)&gt;&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html#a391cb754ab172d1d4cdefd34130b917c">GetKeyType</a></td></tr>
<tr class="separator:a391cb754ab172d1d4cdefd34130b917c"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr class="memitem:a98e54e4e2c19918032b09e23e79a25e5"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html#a98e54e4e2c19918032b09e23e79a25e5">MinQueue</a> (<a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html#a8f2f5b5d2b7097bbc6edda7b9c9228a6">CompareType</a> compare, <a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html#a391cb754ab172d1d4cdefd34130b917c">GetKeyType</a> getKey)</td></tr>
<tr class="memdesc:a98e54e4e2c19918032b09e23e79a25e5"><td class="mdescLeft">&#160;</td><td class="mdescRight">显式构造函数  <a href="#a98e54e4e2c19918032b09e23e79a25e5">More...</a><br /></td></tr>
<tr class="separator:a98e54e4e2c19918032b09e23e79a25e5"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a770243b2227a15bdc2105dde6549c745"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html#a770243b2227a15bdc2105dde6549c745">MinQueue</a> (std::size_t reseve_size, <a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html#a8f2f5b5d2b7097bbc6edda7b9c9228a6">CompareType</a> compare, <a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html#a391cb754ab172d1d4cdefd34130b917c">GetKeyType</a> getKey)</td></tr>
<tr class="memdesc:a770243b2227a15bdc2105dde6549c745"><td class="mdescLeft">&#160;</td><td class="mdescRight">显式构造函数  <a href="#a770243b2227a15bdc2105dde6549c745">More...</a><br /></td></tr>
<tr class="separator:a770243b2227a15bdc2105dde6549c745"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a96293074ee6adef713e9e47059958ea2"><td class="memItemLeft" align="right" valign="top">std::shared_ptr&lt; T &gt;&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html#a96293074ee6adef713e9e47059958ea2">min</a> ()</td></tr>
<tr class="memdesc:a96293074ee6adef713e9e47059958ea2"><td class="mdescLeft">&#160;</td><td class="mdescRight">min:返回最小值  <a href="#a96293074ee6adef713e9e47059958ea2">More...</a><br /></td></tr>
<tr class="separator:a96293074ee6adef713e9e47059958ea2"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a71022b9e1e9993ec5c5876da9e6e6eee"><td class="memItemLeft" align="right" valign="top">std::shared_ptr&lt; T &gt;&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html#a71022b9e1e9993ec5c5876da9e6e6eee">extract_min</a> ()</td></tr>
<tr class="memdesc:a71022b9e1e9993ec5c5876da9e6e6eee"><td class="mdescLeft">&#160;</td><td class="mdescRight">extract_min:删除队列中最小值，并返回最小值  <a href="#a71022b9e1e9993ec5c5876da9e6e6eee">More...</a><br /></td></tr>
<tr class="separator:a71022b9e1e9993ec5c5876da9e6e6eee"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a0992696959d7300082654529becd1765"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html#a0992696959d7300082654529becd1765">insert</a> (std::shared_ptr&lt; T &gt; element)</td></tr>
<tr class="memdesc:a0992696959d7300082654529becd1765"><td class="mdescLeft">&#160;</td><td class="mdescRight">insert:向队列中插入一个元素  <a href="#a0992696959d7300082654529becd1765">More...</a><br /></td></tr>
<tr class="separator:a0992696959d7300082654529becd1765"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a1b484baf6cd011a4b91aa77a644e5a44"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html#a1b484baf6cd011a4b91aa77a644e5a44">is_empty</a> ()</td></tr>
<tr class="memdesc:a1b484baf6cd011a4b91aa77a644e5a44"><td class="mdescLeft">&#160;</td><td class="mdescRight">is_empty:返回队列是否为空  <a href="#a1b484baf6cd011a4b91aa77a644e5a44">More...</a><br /></td></tr>
<tr class="separator:a1b484baf6cd011a4b91aa77a644e5a44"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a545dbdb76e0b6e9c4227e558ab9b1239"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html#a545dbdb76e0b6e9c4227e558ab9b1239">index_inqueue</a> (std::shared_ptr&lt; T &gt; element)</td></tr>
<tr class="memdesc:a545dbdb76e0b6e9c4227e558ab9b1239"><td class="mdescLeft">&#160;</td><td class="mdescRight">is_inqueue:返回指定元素是否在队列中  <a href="#a545dbdb76e0b6e9c4227e558ab9b1239">More...</a><br /></td></tr>
<tr class="separator:a545dbdb76e0b6e9c4227e558ab9b1239"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:aa934049abcfedd59fa9ffe6d91fea30c"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html#aa934049abcfedd59fa9ffe6d91fea30c">decreate_key</a> (std::size_t element_index, TKeyType new_key)</td></tr>
<tr class="memdesc:aa934049abcfedd59fa9ffe6d91fea30c"><td class="mdescLeft">&#160;</td><td class="mdescRight">decreate_key:缩减队列中某个元素的<code>key</code>  <a href="#aa934049abcfedd59fa9ffe6d91fea30c">More...</a><br /></td></tr>
<tr class="separator:aa934049abcfedd59fa9ffe6d91fea30c"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a9a432c7c167a4f9a56c2988cfdc04620"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html#a9a432c7c167a4f9a56c2988cfdc04620">setupHeap</a> ()</td></tr>
<tr class="memdesc:a9a432c7c167a4f9a56c2988cfdc04620"><td class="mdescLeft">&#160;</td><td class="mdescRight">setupHeap:建堆  <a href="#a9a432c7c167a4f9a56c2988cfdc04620">More...</a><br /></td></tr>
<tr class="separator:a9a432c7c167a4f9a56c2988cfdc04620"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a4ddfab80f781d5b5f7544164bf266f82"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html#a4ddfab80f781d5b5f7544164bf266f82">heapify</a> (std::size_t elementIndex)</td></tr>
<tr class="memdesc:a4ddfab80f781d5b5f7544164bf266f82"><td class="mdescLeft">&#160;</td><td class="mdescRight">heapify：维持堆性质  <a href="#a4ddfab80f781d5b5f7544164bf266f82">More...</a><br /></td></tr>
<tr class="separator:a4ddfab80f781d5b5f7544164bf266f82"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pro-methods"></a>
Protected Member Functions</h2></td></tr>
<tr class="memitem:a3b7cac401c8cf45806e61aad3799eda0"><td class="memItemLeft" align="right" valign="top">std::size_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html#a3b7cac401c8cf45806e61aad3799eda0">_parentIndex</a> (std::size_t elementIndex, bool &amp;valid)</td></tr>
<tr class="memdesc:a3b7cac401c8cf45806e61aad3799eda0"><td class="mdescLeft">&#160;</td><td class="mdescRight">_parentIndex:返回一个节点的父节点位置  <a href="#a3b7cac401c8cf45806e61aad3799eda0">More...</a><br /></td></tr>
<tr class="separator:a3b7cac401c8cf45806e61aad3799eda0"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a0d2a517cd63fc33c0403a4d4c83c7e9d"><td class="memItemLeft" align="right" valign="top">std::size_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html#a0d2a517cd63fc33c0403a4d4c83c7e9d">_lchildIndex</a> (std::size_t elementIndex, bool &amp;valid)</td></tr>
<tr class="memdesc:a0d2a517cd63fc33c0403a4d4c83c7e9d"><td class="mdescLeft">&#160;</td><td class="mdescRight">_lchildIndex:返回一个节点的左子节点位置  <a href="#a0d2a517cd63fc33c0403a4d4c83c7e9d">More...</a><br /></td></tr>
<tr class="separator:a0d2a517cd63fc33c0403a4d4c83c7e9d"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a7129becd0fd74b5d2c17702e65f32300"><td class="memItemLeft" align="right" valign="top">std::size_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html#a7129becd0fd74b5d2c17702e65f32300">_rchildIndex</a> (std::size_t elementIndex, bool &amp;valid)</td></tr>
<tr class="memdesc:a7129becd0fd74b5d2c17702e65f32300"><td class="mdescLeft">&#160;</td><td class="mdescRight">_rchildIndex:返回一个节点的右子节点位置  <a href="#a7129becd0fd74b5d2c17702e65f32300">More...</a><br /></td></tr>
<tr class="separator:a7129becd0fd74b5d2c17702e65f32300"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pri-attribs"></a>
Private Attributes</h2></td></tr>
<tr class="memitem:ad463395cef741624e6d078e4e4fc624f"><td class="memItemLeft" align="right" valign="top">std::vector&lt; std::shared_ptr&lt; T &gt; &gt;&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html#ad463395cef741624e6d078e4e4fc624f">_data</a></td></tr>
<tr class="separator:ad463395cef741624e6d078e4e4fc624f"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a0de92802e37516dda2c01de776aba641"><td class="memItemLeft" align="right" valign="top">std::size_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html#a0de92802e37516dda2c01de776aba641">_size</a></td></tr>
<tr class="separator:a0de92802e37516dda2c01de776aba641"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a5de60762d317fc92c18e882dd50f8dfa"><td class="memItemLeft" align="right" valign="top"><a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html#a8f2f5b5d2b7097bbc6edda7b9c9228a6">CompareType</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html#a5de60762d317fc92c18e882dd50f8dfa">_compare</a></td></tr>
<tr class="separator:a5de60762d317fc92c18e882dd50f8dfa"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a3f791f9dd9d61dc2caf1d6b2b354f4c4"><td class="memItemLeft" align="right" valign="top"><a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html#a391cb754ab172d1d4cdefd34130b917c">GetKeyType</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html#a3f791f9dd9d61dc2caf1d6b2b354f4c4">_getKey</a></td></tr>
<tr class="separator:a3f791f9dd9d61dc2caf1d6b2b354f4c4"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><h3>template&lt;typename T, typename TKeyType&gt;<br />
class IntroductionToAlgorithm::QueueAlgorithm::MinQueue&lt; T, TKeyType &gt;</h3>

<p>MinQueue：最小优先级队列，算法导论第6章6.5节 </p>
<p>优先级队列是一种用来维护由一组元素构成集合S的数据结构，其中每个元素都有一个相关的值，称之为关键字。一个最小优先级队列支持以下操作：</p>
<ul>
<li>insert(S,x):将元素x插入到集合S中。</li>
<li>min(S):返回S中具有最小关键字的元素</li>
<li>extract_min(S):去掉并返回S中具有最小关键字的元素</li>
<li>decrease_key(S,x,k):将元素x的关键字值减小到k,这里要求k的值小于x的原始关键字</li>
</ul>
<p>本算法的实现时，有以下几种变化：</p>
<ul>
<li>增加了以下的接口：<ul>
<li>is_empty(S): 返回S是否为空</li>
<li>is_inqueue(S,x):判断元素x是否在S中</li>
<li>setupHeap(S):建立最小堆（由堆的接口遗留而来)</li>
<li>heapify(S,index):操作堆的指定结点使得它符合最小堆条件（由堆的接口遗留下来）</li>
</ul>
</li>
<li>增加了队列容量属性。队列容量由<code>_data</code>的大小来表征。默认将<code>_data</code>大小设为0；可以显式提供<code>reseve_size</code>参数来设置<code>_data</code>的大小。 队列容量用于限制队列大小。一旦队列已满，则下一次插入之前会将队列容量增加一倍；一旦队列不足队列的1/4，则一旦执行<code>extract_min</code>操作则将队列容量缩减至一半</li>
<li>增加了两个特殊的可调用对象，这两个方法的引入使得最小优先级队列不仅可以应用于class和struct类型，也可以应用于int,double等非类的类型<ul>
<li>_getKey:是一个std::function&lt;TKeyType&amp;(std::shared_ptr&lt;T&gt;)&gt;类型的对象，它可以接收std::shared_ptr&lt;T&gt;类型的参数，返回TKeyType类型的引用。 其中队列保存的是T类型数据的强引用，TKeyType是T类型数据的关键字类型。通过_getKey可以获取队列数据的关键字的引用。<ul>
<li>对于class类型，TKeyType就是T对象的关键字类型，_getKey就是返回关键字的引用</li>
<li>对于int等内置类型，TKeyType就是T本身。_getKey就是返回它自身的引用</li>
</ul>
</li>
<li>_compare:是一个std::function&lt;bool (std::shared_ptr&lt;T&gt;,std::shared_ptr&lt;T&gt;)&gt;类型的对象，它用于队列中两个数据的大小比较。 </li>
</ul>
</li>
</ul>

<p>Definition at line <a class="el" href="minqueue_8h_source.html#l00060">60</a> of file <a class="el" href="minqueue_8h_source.html">minqueue.h</a>.</p>
</div><h2 class="groupheader">Member Typedef Documentation</h2>
<a class="anchor" id="a8f2f5b5d2b7097bbc6edda7b9c9228a6"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T, typename TKeyType&gt; </div>
      <table class="memname">
        <tr>
          <td class="memname">typedef std::function&lt;bool (std::shared_ptr&lt;T&gt;,std::shared_ptr&lt;T&gt;)&gt; <a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html">IntroductionToAlgorithm::QueueAlgorithm::MinQueue</a>&lt; T, TKeyType &gt;::<a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html#a8f2f5b5d2b7097bbc6edda7b9c9228a6">CompareType</a></td>
        </tr>
      </table>
</div><div class="memdoc">
<p>一个可调用对象类型，该类型的对象可用于比较两个std::shared_ptr&lt;T&gt;的小于比较 </p>

<p>Definition at line <a class="el" href="minqueue_8h_source.html#l00063">63</a> of file <a class="el" href="minqueue_8h_source.html">minqueue.h</a>.</p>

</div>
</div>
<a class="anchor" id="a391cb754ab172d1d4cdefd34130b917c"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T, typename TKeyType&gt; </div>
      <table class="memname">
        <tr>
          <td class="memname">typedef std::function&lt;TKeyType&amp;(std::shared_ptr&lt;T&gt;)&gt; <a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html">IntroductionToAlgorithm::QueueAlgorithm::MinQueue</a>&lt; T, TKeyType &gt;::<a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html#a391cb754ab172d1d4cdefd34130b917c">GetKeyType</a></td>
        </tr>
      </table>
</div><div class="memdoc">
<p>一个可调用对象，该类型的对象可用于获取std::shared_ptr&lt;T&gt;的关键字，并修改该关键字（返回的是关键字的引用） </p>

<p>Definition at line <a class="el" href="minqueue_8h_source.html#l00064">64</a> of file <a class="el" href="minqueue_8h_source.html">minqueue.h</a>.</p>

</div>
</div>
<h2 class="groupheader">Constructor &amp; Destructor Documentation</h2>
<a class="anchor" id="a98e54e4e2c19918032b09e23e79a25e5"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T, typename TKeyType&gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html">IntroductionToAlgorithm::QueueAlgorithm::MinQueue</a>&lt; T, TKeyType &gt;::<a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html">MinQueue</a> </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html#a8f2f5b5d2b7097bbc6edda7b9c9228a6">CompareType</a>&#160;</td>
          <td class="paramname"><em>compare</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html#a391cb754ab172d1d4cdefd34130b917c">GetKeyType</a>&#160;</td>
          <td class="paramname"><em>getKey</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>显式构造函数 </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">compare:一个可调用对象，可用于比较两个std::shared_ptr&lt;T&gt;对象的小于比较</td><td></td></tr>
    <tr><td class="paramname">getKey：一个可调用对象，它的参数为std::shared_ptr&lt;T&gt;，返回TKey&amp;。通过它的返回值可以获取T的key，也可以修改T的key</td><td></td></tr>
  </table>
  </dd>
</dl>

<p>Definition at line <a class="el" href="minqueue_8h_source.html#l00071">71</a> of file <a class="el" href="minqueue_8h_source.html">minqueue.h</a>.</p>

</div>
</div>
<a class="anchor" id="a770243b2227a15bdc2105dde6549c745"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T, typename TKeyType&gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html">IntroductionToAlgorithm::QueueAlgorithm::MinQueue</a>&lt; T, TKeyType &gt;::<a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html">MinQueue</a> </td>
          <td>(</td>
          <td class="paramtype">std::size_t&#160;</td>
          <td class="paramname"><em>reseve_size</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html#a8f2f5b5d2b7097bbc6edda7b9c9228a6">CompareType</a>&#160;</td>
          <td class="paramname"><em>compare</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html#a391cb754ab172d1d4cdefd34130b917c">GetKeyType</a>&#160;</td>
          <td class="paramname"><em>getKey</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>显式构造函数 </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">reseve_size:指定队列的初始容量</td><td></td></tr>
    <tr><td class="paramname">compare:一个可调用对象，可用于比较两个std::shared_ptr&lt;T&gt;对象的小于比较</td><td></td></tr>
    <tr><td class="paramname">getKey：一个可调用对象，它的参数为std::shared_ptr&lt;T&gt;，返回TKey&amp;。通过它的返回值可以获取T的key，也可以修改T的key</td><td></td></tr>
  </table>
  </dd>
</dl>

<p>Definition at line <a class="el" href="minqueue_8h_source.html#l00079">79</a> of file <a class="el" href="minqueue_8h_source.html">minqueue.h</a>.</p>

</div>
</div>
<h2 class="groupheader">Member Function Documentation</h2>
<a class="anchor" id="a0d2a517cd63fc33c0403a4d4c83c7e9d"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T, typename TKeyType&gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">std::size_t <a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html">IntroductionToAlgorithm::QueueAlgorithm::MinQueue</a>&lt; T, TKeyType &gt;::_lchildIndex </td>
          <td>(</td>
          <td class="paramtype">std::size_t&#160;</td>
          <td class="paramname"><em>elementIndex</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">bool &amp;&#160;</td>
          <td class="paramname"><em>valid</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span><span class="mlabel">protected</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>_lchildIndex:返回一个节点的左子节点位置 </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">elementIndex</td><td>: 节点位置 </td></tr>
    <tr><td class="paramname">valid</td><td>一个bool&amp;值，用于返回，指示子节点是否有效 </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>左子节点位置(std::size_t)</dd></dl>
<p>根据最小堆的性质，一个节点elementIndex的左子节点是它的位置(elementIndex/2)+1</p>
<ul>
<li>当最小堆大小为0、1时，它没有左子节点，左子节点无效</li>
<li>当左子节点超过堆大小时，它无效 </li>
</ul>

<p>Definition at line <a class="el" href="minqueue_8h_source.html#l00326">326</a> of file <a class="el" href="minqueue_8h_source.html">minqueue.h</a>.</p>

</div>
</div>
<a class="anchor" id="a3b7cac401c8cf45806e61aad3799eda0"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T, typename TKeyType&gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">std::size_t <a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html">IntroductionToAlgorithm::QueueAlgorithm::MinQueue</a>&lt; T, TKeyType &gt;::_parentIndex </td>
          <td>(</td>
          <td class="paramtype">std::size_t&#160;</td>
          <td class="paramname"><em>elementIndex</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">bool &amp;&#160;</td>
          <td class="paramname"><em>valid</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span><span class="mlabel">protected</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>_parentIndex:返回一个节点的父节点位置 </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">elementIndex</td><td>: 子节点位置 </td></tr>
    <tr><td class="paramname">valid</td><td>一个bool&amp;值，用于返回，指示父节点是否有效 </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>父节点位置(std::size_t)</dd></dl>
<p>根据最小堆的性质，一个子节点elementIndex的父节点是它的位置(elementIndex-1)/2。</p>
<ul>
<li>超出堆大小的节点，其父节点无效 </li>
</ul>

<p>Definition at line <a class="el" href="minqueue_8h_source.html#l00303">303</a> of file <a class="el" href="minqueue_8h_source.html">minqueue.h</a>.</p>

</div>
</div>
<a class="anchor" id="a7129becd0fd74b5d2c17702e65f32300"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T, typename TKeyType&gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">std::size_t <a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html">IntroductionToAlgorithm::QueueAlgorithm::MinQueue</a>&lt; T, TKeyType &gt;::_rchildIndex </td>
          <td>(</td>
          <td class="paramtype">std::size_t&#160;</td>
          <td class="paramname"><em>elementIndex</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">bool &amp;&#160;</td>
          <td class="paramname"><em>valid</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span><span class="mlabel">protected</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>_rchildIndex:返回一个节点的右子节点位置 </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">elementIndex</td><td>: 节点位置 </td></tr>
    <tr><td class="paramname">valid</td><td>一个bool&amp;值，用于返回，指示子节点是否有效 </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>右子节点位置(std::size_t)</dd></dl>
<p>根据最小堆的性质，一个节点elementIndex的右子节点是它的位置(elementIndex/2)+2</p>
<ul>
<li>当最小堆大小为0、、1、2时，它没有右子节点，右子节点无效</li>
<li>当右子节点超过堆大小时，它无效 </li>
</ul>

<p>Definition at line <a class="el" href="minqueue_8h_source.html#l00353">353</a> of file <a class="el" href="minqueue_8h_source.html">minqueue.h</a>.</p>

</div>
</div>
<a class="anchor" id="aa934049abcfedd59fa9ffe6d91fea30c"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T, typename TKeyType&gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">void <a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html">IntroductionToAlgorithm::QueueAlgorithm::MinQueue</a>&lt; T, TKeyType &gt;::decreate_key </td>
          <td>(</td>
          <td class="paramtype">std::size_t&#160;</td>
          <td class="paramname"><em>element_index</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">TKeyType&#160;</td>
          <td class="paramname"><em>new_key</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>decreate_key:缩减队列中某个元素的<code>key</code> </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">element_index</td><td>待缩减元素的下标 </td></tr>
    <tr><td class="paramname">new_key：待缩减元素的新&lt;tt&gt;key&lt;/tt&gt;，类型为TKey</td><td>缩减之前先判断缩减是否有效，若无效则抛出异常。</td></tr>
  </table>
  </dd>
</dl>
<ul>
<li>若<code>element_index</code>超过了队列大小，则抛出异常</li>
<li>若<code>new_key</code>大于等于待缩减元素的<code>key</code>，则抛出异常</li>
</ul>
<p>缩减过程为：</p>
<ul>
<li>将待缩减元素的<code>key</code>赋值为新值</li>
<li>不断的将该元素向父节点比较：<ul>
<li>若父节点较小，则终止比较过程</li>
<li>若父节点较大，则交换当前节点与父节点，并将当前节点指向父节点进行下一轮比较</li>
<li>若当前节点已经是队列首个元素，则终止比较过程</li>
</ul>
</li>
<li>时间复杂度 O(h)</li>
<li>原地操作 </li>
</ul>

<p>Definition at line <a class="el" href="minqueue_8h_source.html#l00216">216</a> of file <a class="el" href="minqueue_8h_source.html">minqueue.h</a>.</p>

</div>
</div>
<a class="anchor" id="a71022b9e1e9993ec5c5876da9e6e6eee"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T, typename TKeyType&gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">std::shared_ptr&lt;T&gt; <a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html">IntroductionToAlgorithm::QueueAlgorithm::MinQueue</a>&lt; T, TKeyType &gt;::extract_min </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>extract_min:删除队列中最小值，并返回最小值 </p>
<dl class="section return"><dt>Returns</dt><dd>最小值的强引用</dd></dl>
<p>根据最小堆的性质，队列的第一个值就是最小值的强引用。</p>
<ul>
<li>如果队列为空，则返回一个空引用</li>
<li>如果队列非空，则执行以下操作：<ul>
<li>交换队列的第一个元素和最后一个元素</li>
<li>队列的<code>_size</code>自减</li>
<li>此时队列的首个元素违反了最小堆性质，因此执行<code>heapify(0)</code>保持性质</li>
<li>返回旧的首个元素</li>
</ul>
</li>
</ul>
<p>一旦队列长度不足容量的1/4，则将队列容量设置为队列长度的一倍（为了防止极端情况，如_size=0，此时将队列容量设为队列长度的一倍加上2）</p>
<ul>
<li>时间复杂度 O(h),h为堆的高度</li>
<li>原地操作 </li>
</ul>

<p>Definition at line <a class="el" href="minqueue_8h_source.html#l00116">116</a> of file <a class="el" href="minqueue_8h_source.html">minqueue.h</a>.</p>

</div>
</div>
<a class="anchor" id="a4ddfab80f781d5b5f7544164bf266f82"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T, typename TKeyType&gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">void <a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html">IntroductionToAlgorithm::QueueAlgorithm::MinQueue</a>&lt; T, TKeyType &gt;::heapify </td>
          <td>(</td>
          <td class="paramtype">std::size_t&#160;</td>
          <td class="paramname"><em>elementIndex</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>heapify：维持堆性质 </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">elementIndex</td><td>: 要维持以该节点为根节点的子堆的堆性质 </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>void</dd></dl>
<p>首先调用比较该节点与左右子节点的最小值。如果最小值为它本身，则维持了性质，返回；如果最小值不是它本身，那么必然为左、右子节点之一。 将该最小节点（假设为左子节点）交换到根节点，然后以左子节点递归调用heapify操作</p>
<ul>
<li>时间复杂度 O(n)</li>
<li>原地操作 </li>
</ul>

<p>Definition at line <a class="el" href="minqueue_8h_source.html#l00265">265</a> of file <a class="el" href="minqueue_8h_source.html">minqueue.h</a>.</p>

</div>
</div>
<a class="anchor" id="a545dbdb76e0b6e9c4227e558ab9b1239"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T, typename TKeyType&gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">int <a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html">IntroductionToAlgorithm::QueueAlgorithm::MinQueue</a>&lt; T, TKeyType &gt;::index_inqueue </td>
          <td>(</td>
          <td class="paramtype">std::shared_ptr&lt; T &gt;&#160;</td>
          <td class="paramname"><em>element</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>is_inqueue:返回指定元素是否在队列中 </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">element:待判定的元素，要求非空。若它为空引用则抛出异常</td><td></td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>指定元素在队列中的下标</dd></dl>
<p>从前到后依次遍历队列，如果队列中某个元素等于<code>element</code>，则返回非负整数值， 代表它在队列的std::vector中的位置；否则返回-1</p>
<ul>
<li>时间复杂度 O(h) </li>
</ul>

<p>Definition at line <a class="el" href="minqueue_8h_source.html#l00185">185</a> of file <a class="el" href="minqueue_8h_source.html">minqueue.h</a>.</p>

</div>
</div>
<a class="anchor" id="a0992696959d7300082654529becd1765"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T, typename TKeyType&gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">int <a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html">IntroductionToAlgorithm::QueueAlgorithm::MinQueue</a>&lt; T, TKeyType &gt;::insert </td>
          <td>(</td>
          <td class="paramtype">std::shared_ptr&lt; T &gt;&#160;</td>
          <td class="paramname"><em>element</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>insert:向队列中插入一个元素 </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">element</td><td>待插入元素，如果元素为空引用则直接返回 </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>: 插入的元素在队列中的位置。若元素为空指针则返回-1</dd></dl>
<p>插入之前首先判断队列是否已满。若队列已满，则将<code>_data</code>扩容为大小<code>_size*2+2</code>。</p>
<ul>
<li>若<code>_size==_data.size()</code>则说明队列已满</li>
</ul>
<p>插入过程为：</p>
<ul>
<li>保留待插入元素的<code>key</code>，同时将待插入语元素的<code>key</code>设置为无穷大，并将待插入元素插入到队尾</li>
<li>执行<code>decreate_key(..)</code>操作</li>
</ul>
<p>一旦队列已满，则将队列容量设置为队列长度的一倍（为了防止极端情况，如_size=0，此时将队列容量设为队列长度的一倍加上2）</p>
<ul>
<li>时间复杂度 O(h)</li>
<li>原地操作 </li>
</ul>

<p>Definition at line <a class="el" href="minqueue_8h_source.html#l00148">148</a> of file <a class="el" href="minqueue_8h_source.html">minqueue.h</a>.</p>

</div>
</div>
<a class="anchor" id="a1b484baf6cd011a4b91aa77a644e5a44"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T, typename TKeyType&gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">bool <a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html">IntroductionToAlgorithm::QueueAlgorithm::MinQueue</a>&lt; T, TKeyType &gt;::is_empty </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>is_empty:返回队列是否为空 </p>
<dl class="section return"><dt>Returns</dt><dd>队列是否为空</dd></dl>
<p>若队列的<code>_size</code>为0，则队列为空；否则队列不为空</p>
<ul>
<li>时间复杂度 O(1) </li>
</ul>

<p>Definition at line <a class="el" href="minqueue_8h_source.html#l00170">170</a> of file <a class="el" href="minqueue_8h_source.html">minqueue.h</a>.</p>

</div>
</div>
<a class="anchor" id="a96293074ee6adef713e9e47059958ea2"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T, typename TKeyType&gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">std::shared_ptr&lt;T&gt; <a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html">IntroductionToAlgorithm::QueueAlgorithm::MinQueue</a>&lt; T, TKeyType &gt;::min </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>min:返回最小值 </p>
<dl class="section return"><dt>Returns</dt><dd>最小值的强引用</dd></dl>
<p>根据最小堆的性质，队列的第一个值就是最小值的强引用。如果队列为空，则返回一个空引用</p>
<ul>
<li>时间复杂度 O(1) </li>
</ul>

<p>Definition at line <a class="el" href="minqueue_8h_source.html#l00092">92</a> of file <a class="el" href="minqueue_8h_source.html">minqueue.h</a>.</p>

</div>
</div>
<a class="anchor" id="a9a432c7c167a4f9a56c2988cfdc04620"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T, typename TKeyType&gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">void <a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html">IntroductionToAlgorithm::QueueAlgorithm::MinQueue</a>&lt; T, TKeyType &gt;::setupHeap </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>setupHeap:建堆 </p>
<dl class="section return"><dt>Returns</dt><dd>void</dd></dl>
<p>从后一半的元素开始依次向前调用heapify操作（根据最小堆性质，除了最底层它是完全充满的）</p>
<ul>
<li>时间复杂度 O(nlogn)</li>
<li>原地操作 </li>
</ul>

<p>Definition at line <a class="el" href="minqueue_8h_source.html#l00243">243</a> of file <a class="el" href="minqueue_8h_source.html">minqueue.h</a>.</p>

</div>
</div>
<h2 class="groupheader">Member Data Documentation</h2>
<a class="anchor" id="a5de60762d317fc92c18e882dd50f8dfa"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T, typename TKeyType&gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html#a8f2f5b5d2b7097bbc6edda7b9c9228a6">CompareType</a> <a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html">IntroductionToAlgorithm::QueueAlgorithm::MinQueue</a>&lt; T, TKeyType &gt;::_compare</td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">private</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">
<p>一个可调用对象，可用于比较两个std::shared_ptr&lt;T&gt;的小于比较 </p>

<p>Definition at line <a class="el" href="minqueue_8h_source.html#l00371">371</a> of file <a class="el" href="minqueue_8h_source.html">minqueue.h</a>.</p>

</div>
</div>
<a class="anchor" id="ad463395cef741624e6d078e4e4fc624f"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T, typename TKeyType&gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">std::vector&lt;std::shared_ptr&lt;T&gt; &gt; <a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html">IntroductionToAlgorithm::QueueAlgorithm::MinQueue</a>&lt; T, TKeyType &gt;::_data</td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">private</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">
<p>最小优先级队列的数据 </p>

<p>Definition at line <a class="el" href="minqueue_8h_source.html#l00369">369</a> of file <a class="el" href="minqueue_8h_source.html">minqueue.h</a>.</p>

</div>
</div>
<a class="anchor" id="a3f791f9dd9d61dc2caf1d6b2b354f4c4"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T, typename TKeyType&gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html#a391cb754ab172d1d4cdefd34130b917c">GetKeyType</a> <a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html">IntroductionToAlgorithm::QueueAlgorithm::MinQueue</a>&lt; T, TKeyType &gt;::_getKey</td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">private</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">
<p>一个可调用对象，可用于获取std::shared_ptr&lt;T&gt;的关键字，并修改该关键字（返回的是关键字的引用） </p>

<p>Definition at line <a class="el" href="minqueue_8h_source.html#l00372">372</a> of file <a class="el" href="minqueue_8h_source.html">minqueue.h</a>.</p>

</div>
</div>
<a class="anchor" id="a0de92802e37516dda2c01de776aba641"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T, typename TKeyType&gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">std::size_t <a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html">IntroductionToAlgorithm::QueueAlgorithm::MinQueue</a>&lt; T, TKeyType &gt;::_size</td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">private</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">
<p>堆大小 </p>

<p>Definition at line <a class="el" href="minqueue_8h_source.html#l00370">370</a> of file <a class="el" href="minqueue_8h_source.html">minqueue.h</a>.</p>

</div>
</div>
<hr/>The documentation for this class was generated from the following file:<ul>
<li>src/queue_algorithms/min_queue/<a class="el" href="minqueue_8h_source.html">minqueue.h</a></li>
</ul>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="namespace_introduction_to_algorithm.html">IntroductionToAlgorithm</a></li><li class="navelem"><a class="el" href="namespace_introduction_to_algorithm_1_1_queue_algorithm.html">QueueAlgorithm</a></li><li class="navelem"><a class="el" href="class_introduction_to_algorithm_1_1_queue_algorithm_1_1_min_queue.html">MinQueue</a></li>
    <li class="footer">Generated by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.10 </li>
  </ul>
</div>
</body>
</html>
